package com.directv.z8training.EMS.DAO;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Repository;

import com.directv.z8training.EMS.Entity.Project;
import com.directv.z8training.EMS.Entity.ProjectUser;
import com.directv.z8training.EMS.Entity.ProjectUserPK;

@Repository
public class ProjectDAOImpl implements ProjectDAO {
	
	@PersistenceContext
	EntityManager entityManager;

	@Override
	public void createProject(String username, String code, String description, Date startdate,
			Date enddate) throws SQLException {
		// TODO Auto-generated method stub
		Project project = new Project();
		project.setCode(code);
		project.setDescirption(description);
		project.setStartdate(startdate);
		project.setEnddate(enddate);
		
		List<ProjectUser> projectUsers = new ArrayList<ProjectUser>();
		ProjectUser proUser = new ProjectUser();
		ProjectUserPK proUserPK = new ProjectUserPK();
		proUserPK.setUsername(username);
		proUserPK.setProjectcode(code);

		proUser.setId(proUserPK);
		projectUsers.add(proUser);
		project.setProjectUsers(projectUsers);
		try {
			entityManager.persist(project);
		} catch (Exception e) {
			throw new SQLException();
		}
	}
	
	
}
